<?php
  $objXajax->registerFunction("fmfrmglass_save");
  $objXajax->registerFunction("fmfrmglass_edit");
  $objXajax->registerFunction("fmfrmglass_delete");
  $objXajax->registerFunction("fmfrmglass_loadGrid");    
  function fmfrmglass_save($params){
    global $objDbUpdate,$tbl_postfix,$hotel_id;
      
    $objResponse = new xajaxResponse();
    $name = addslashes($params['name']);
    $extprice = $params['extprice'];
    $edit = $params['hdEdit'];
    $id = $params['hdId'];
    //$strValue = fmfrmglass_createValue($strname,$filmtype_id);
    $sqlInsert ='';
    if($edit==0){
      $sqlInsert = "insert into fm_glass(name,extprice,service_id) value('$name','$extprice','$hotel_id')";  
    }else{
      $sqlInsert = "update fm_glass set name = '$name', extprice = '$extprice' where id = $id"; 
    }
    
    $flag = $objDbUpdate->Execute($sqlInsert);
    $objResponse->addScript('xajax_fmfrmglass_loadGrid();');
    return $objResponse->getXML(); 
  }
  
  function fmfrmglass_createValue($strname,$filmtype_id){
      $strname = str_replace(',',';',$strname);
      $arrname = explode(';',$strname);
      $result ='';
      for($i=0;$i<count($arrname);$i++){
          $name =trim($arrname[$i]) ;
          if($name!=''){
              $result .= ",('$name',$filmtype_id)"; 
          }         
      }
      if(strlen($result)>0){
        $result = substr($result,1);  
      }
      return $result;
  }
  
   function fmfrmglass_loadGrid(){
    global $lang;
    $objResponse = new xajaxResponse();
    $arrGrid = fmfrmglass_GetGrid();
    $oTbs = new clsTinyButStrong();
    $oTbs->LoadTemplate('templates/'.$lang.'/customer/fm_glass_grid.html');
    $oTbs->MergeBlock('blk_data', $arrGrid);
    $oTbs->Show(TBS_NOTHING);
    $objResponse->addAssign('fmfrmglass_divGrid', 'innerHTML', $oTbs->Source);
    $objResponse->addScriptCall("dataTableObj.CreatDataTable('fmfrmglass_tbl');"); 
    $objResponse->addScript('changeWaiting(1);');                              
    return $objResponse->getXML(); // dong luon luon co khi goi ham ajax   
  }
  
    function  fmfrmglass_GetGrid(){
        global $objDbSelect,$tbl_postfix,$hotel_id;
        $sqlSelect = "select *,if(extprice>0,1,'') as useglass from 
        fm_glass where service_id = $hotel_id  order by name";
        $arr = $objDbSelect->GetArray($sqlSelect);
        return $arr;
    }
    function fmfrmglass_delete($strId){
        global $objDbSelect,$tbl_postfix;
       $objResponse = new xajaxResponse();
       $sql = " delete from fm_glass where id in ($strId) " ;
       $objDbSelect->Execute($sql);
       $objResponse->addScript('changeWaiting(1);');
       $objResponse->addScript('deleteRowlogic();');
       return $objResponse->getXML(); // dong luon luon co khi goi ham ajax  
    }
    
     function fmfrmglass_edit($id){
        global $objDbSelect,$tbl_postfix;
        $objResponse = new xajaxResponse();
        $sql = " SELECT * FROM fm_glass WHERE id = '$id' ";
        $arr = $objDbSelect->GetArray($sql);
        $roomname        = $arr[0]['name'];
        $extprice   = $arr[0]['extprice'];
        $objResponse->addScript("$('#fmfrmglass_name').val('$roomname');");
        $objResponse->addScript("$('#fmfrmglass_extprice').val('$extprice');");
        if($extprice!=0){
           $objResponse->addScript("$('#fmfrmglass_chkUserGlass').attr('checked','checked');"); 
           $objResponse->addScript("$('#fmfrmglass_trextprice').show();"); 
        }else{
          $objResponse->addScript("$('#fmfrmglass_chkUserGlass').attr('checked',false);"); 
           $objResponse->addScript("$('#fmfrmglass_trextprice').hide();");  
        }
       // $objResponse->addScript("$('#fmfrmglass_name').val('$roomname');");
        $objResponse->addScript('changeWaiting(1);');
        return $objResponse->getXML();   
    }

?>
